<template>
    <el-dialog :visible.sync="isShow" :title="headerTitle" @close="handleClose" center top="14vh" width="400px" append-to-body :fullscreen="fullscreen">
        <el-form :model="dialogForm" size="small" label-suffix=":" ref="detailForm" :rules="rules" label-width="80px">
            <!--              厂区类型-->
            <el-form-item label="厂区类型" prop="factoryCategory">
                <el-input v-model="dialogForm.factoryCategory" placeholder="请输入厂区类型" clearable />
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm" :loading="loading" icon="el-icon-document" size="small">{{$t('public.save')}}</el-button>
        </div>
    </el-dialog>
</template>

<script>
import { listAllGaugeMessage } from '@/api/basic/gaugeMessage'
import { addGauge, modGauge } from '@/api/basic/gauge'
import { updateFactory } from '@/api/basic/factory'

export default {
    name: 'mtool-detial',
    dicts: [],
    props: {
        value: {
            type: Object,
        },
        visible: {
            type: Boolean,
            default: false,
        },
        type: [String, Number], //1:新增  2：编辑 3：查看
    },
    watch: {
        value(val) {
            this.dialogForm = { ...val }
        },
    },
    computed: {
        isShow: {
            get() {
                return this.visible
            },
            set() {},
        },
        headerTitle() {
            const { type } = this
            let title = ''
            if (type == 1) {
                title = '新增厂区'
            }
            if (type == 2) {
                title = '编辑厂区'
            }
            if (type == 3) {
                title = '查看厂区'
            }
            return title
        },
    },
    data() {
        return {
            loading: false,
            fullscreen: false,
            deviceOptions: undefined,
            factoryOptions: undefined,
            dialogForm: {},
            // 表单校验
            rules: {
                factoryCategory: [
                    {
                        required: true,
                        message: '厂区类型不能为空',
                        trigger: 'blur',
                    },
                ],
            },
        }
    },
    methods: {
        /** 发起提交 */
        submitForm: function () {
            this.$refs.detailForm.validate((valid) => {
                if (valid) {
                    this.loading = true
                    updateFactory(this.dialogForm).then((res) => {
                        this.loading = false
                        if (res.code == 200) {
                            this.$emit('refresh')
                            this.$modal.msgSuccess('操作成功!')
                            this.$emit('update:visible', false)
                        } else {
                            this.$modal.msgError(res.msg)
                        }
                    })
                }
            })
        },
        handleClose(done) {
            this.$refs.detailForm.clearValidate()
            this.$emit('update:visible', false)
        },
    },
}
</script>

<style scoped>
</style>
